class Solution(object):
    def countHillValley(self, nums):
        state = 0
        ans = 0
        n = len(nums)
        for i in range(1, n):
            if nums[i] > nums[i - 1]:
                if state == 1:
                    state = 2
                    ans += 1
                else:
                    state = 2
            else:
                if nums[i] < nums[i - 1]:
                    if state == 2:
                        state = 1
                        ans += 1
                    else:
                        state = 1
        return ans



